﻿using DeviceDebugger.DataAccess;
using DeviceDebugger.Model.Enums;
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceDebugger.Model
{
    /// <summary>
    /// 调试记录
    /// </summary>
    public class RunLogs : ObservableObject
    {
        private Int64 _id;
        public Int64 Id
        {
            get { return _id; }
            set { _id = value; RaisePropertyChanged(() => Id); }
        }
        private Int64 _stackerId;
        public Int64 StackerId
        {
            get { return _stackerId; }
            set { _stackerId = value; RaisePropertyChanged(() => StackerId); }
        }

        private DateTime _happenTime;
        /// <summary>
        /// 发生时间
        /// </summary>
        public DateTime HappenTime
        {
            get { return _happenTime; }
            set { _happenTime = value; RaisePropertyChanged(() => HappenTime); }
        }


        private string _logsText;
        /// <summary>
        /// 记录下的文本
        /// </summary>
        public string LogsText
        {
            get { return _logsText; }
            set { _logsText = value; RaisePropertyChanged(() => LogsText); }
        }


        private LogsTypeEnum _logsType;
        /// <summary>
        /// 日志类别，1：信息；2：故障
        /// </summary>
        public LogsTypeEnum LogsType
        {
            get { return _logsType; }
            set { _logsType = value; RaisePropertyChanged(() => LogsType); }
        }


        /// <summary>
        /// 调试记录实体，并插入到数据库中
        /// </summary>
        /// <param name="time"></param>
        /// <param name="logText"></param>
        public RunLogs(Int64 stackerId, DateTime time, string logText, LogsTypeEnum logsTypeEnum = LogsTypeEnum.信息)
        {
            this.StackerId = stackerId;
            this.HappenTime = time;
            this.LogsText = logText;
            this.LogsType = logsTypeEnum;

            DataVisitor.AddRunLogs(this);
        }
    }
}
